package homework.test1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*
1. 使用Map<String,String> map = new HashMap<>();
    "itheima001","小智"
    "itheima002","小美"
    "itheima003","大胖"
    "itheima004","小黑"
    "itheima005","大师"
要求:
	使用keySet()方法遍历集合
	使用entrySet()方法遍历集合
	使用foreach()方法遍历集合
 */
public class Demo1 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();

        map.put("itheima001","小智");
        map.put("itheima002","小美");
        map.put("itheima003","大胖");
        map.put("itheima004","小黑");
        map.put("itheima005","大师");

        //1.使用keySet()方法遍历集合
        Set<String> set = map.keySet();
        Iterator<String> it1 = set.iterator();
        while (it1.hasNext()){
            String key = it1.next();
            String value = map.get(key);
            System.out.println(key+"..."+value);
        }

        System.out.println("----------------------------------------------");

        //2.使用entrySet()方法遍历集合
        Set<Map.Entry<String,String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> it2 = entries.iterator();
        while (it2.hasNext()){
            Map.Entry<String,String> entry = it2.next();
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"..."+value);
        }

        System.out.println("----------------------------------------------");

        //3.使用foreach()方法遍历集合
        map.forEach((key,value)-> System.out.println(key+"..."+value));
    }
}
